package com.cloudsigns.factorymanager2.project.activity;

import android.app.Activity;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.cloudsigns.factorymanager2.R;
import com.cloudsigns.factorymanager2.project.customview.TitleDialog;
import com.cloudsigns.factorymanager2.project.customview.WorkSheetCategoryPoupWindow;
import com.cloudsigns.factorymanager2.project.utils.ConstantUtil;

/**
 * 项目总控表
 * Created by tony on 2017/12/16.
 */

public class ProjectMasterScheduleActivity extends Activity implements View.OnClickListener {
    private RelativeLayout rl_right;
    private ImageView img_right;
    private ImageView img_back;
    private TextView tv_title;
    private RelativeLayout rl_content;
    private TextView tv_engineering_name;
    private RelativeLayout rl_engineering_name;
    private TitleDialog titleDialog;
    String projectName = "", engineeringName = "";
    private WorkSheetCategoryPoupWindow workSheetPopupwindow;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏
        // 沉浸式状态栏
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
                    );
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN

                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(Color.TRANSPARENT);

        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }
        setContentView(R.layout.layout_engineering_master_schedule);

        init();
    }


    private void init() {
        img_back = findViewById(R.id.img_back);
        rl_right = findViewById(R.id.rl_right);
        img_right = findViewById(R.id.img_right);
        tv_title = findViewById(R.id.tv_title);
        rl_content = findViewById(R.id.rl_content);
        tv_engineering_name = findViewById(R.id.tv_engineering_name);
        rl_engineering_name = findViewById(R.id.rl_engineering_name);


        tv_title.setText(getResources().getText(R.string.engineering_master_schedule));
        img_right.setBackgroundResource(R.mipmap.icon_funnel);
        img_back.setOnClickListener(this);
        rl_right.setOnClickListener(this);
        rl_engineering_name.setOnClickListener(this);
    }

    private void showEngineeringPoupWindow(View anchor) {
        workSheetPopupwindow = new WorkSheetCategoryPoupWindow(this);
        workSheetPopupwindow.setOnClickListener(this);
        workSheetPopupwindow.showPopupWindow(anchor);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.img_back:
                finish();
                break;
            case R.id.rl_right:
//                showTitleDialog();

                break;
            case R.id.rl_engineering_name: //选择
                showEngineeringPoupWindow(view);
                break;
        }
    }

    private void showTitleDialog() {
        titleDialog = new TitleDialog(ProjectMasterScheduleActivity.this);
        titleDialog.createProjectManagerTitleDialog(new TitleDialog.OnButtonClickListener() {
            @Override
            public void onButtonClick(Bundle bundle) {
                if (null != bundle) {
                    projectName = bundle.getString(ConstantUtil.PROJECT_NAME);
                    engineeringName = bundle.getString(ConstantUtil.ENGINEERING_NAME);

                    tv_engineering_name.setText(projectName + "/" + engineeringName);
                    rl_content.setVisibility(View.VISIBLE);
                }
            }
        });

        titleDialog.show();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (titleDialog != null) {
            titleDialog.dismiss();
            titleDialog = null;
        }

        if (workSheetPopupwindow != null) {
            workSheetPopupwindow.dismiss();
            workSheetPopupwindow = null;
        }

    }
}
